package kr.pe.johnkim.chattingday.mobile.rest.dao;

import kr.pe.johnkim.chattingday.mobile.domain.ChattingDayGatheringMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

/**
 * @author : johnkim <cale9797@gmail.com / Bettersoft Inc,.>
 * @Date : 12. 6. 12
 */
public class ChattingDayGatheringMessageDaoImpl extends SqlMapClientDaoSupport implements ChattingDayGatheringMessageDao {

    // SLF4J logging
    private Logger logger = LoggerFactory.getLogger(ChattingDayGatheringMessageDaoImpl.class);
    
    /**
     * 채팅방에 메시지를 남긴다.
     *
     * @param chattingDayGatheringMessage
     * @return
     */
    @Override
    public boolean registerGatheringMessage(ChattingDayGatheringMessage chattingDayGatheringMessage) {
        logger.info("registerGatheringMessage");

        boolean result;

        try {
            getSqlMapClientTemplate().insert("CHATTINGDAY_GATHERING_MESSAGES.registerGatheringMessage", chattingDayGatheringMessage);
            result = true;
        } catch (Exception e) {
            result = false;
        }

        return result;
    }

    /**
     * 메시지를 비활성화 한다.
     *
     * @param chattingDayGatheringMessage
     * @return
     */
    @Override
    public boolean updateDeactivateGatheringMessage(ChattingDayGatheringMessage chattingDayGatheringMessage) {
        logger.info("updateDeactivateGatheringMessage");

        boolean result;

        try {
            getSqlMapClientTemplate().update("CHATTINGDAY_GATHERING_MESSAGES.updateDeactivateGatheringMessage", chattingDayGatheringMessage);
            result = true;
        } catch (Exception e) {
            result = false;
        }

        return result;
    }

    /**
     * 채팅방의 모든 메시지를 비활성화 한다.
     * <p/>
     * 방장(채팅방 개설자)일 경우 가능.
     *
     * @param chattingDayGatheringMessage
     * @return
     */
    @Override
    public boolean updateDeactivateAllGatheringMessage(ChattingDayGatheringMessage chattingDayGatheringMessage) {
        logger.info("updateDeactivateAllGatheringMessage");

        boolean result;

        try {
            getSqlMapClientTemplate().update("CHATTINGDAY_GATHERING_MESSAGES.updateDeactivateAllGatheringMessage", chattingDayGatheringMessage);
            result = true;
        } catch (Exception e) {
            result = false;
        }

        return result;
    }
}
